let arr = [1, 2, 3, 4, 5];
let arr1 = [6, 7, 8];
let arr2 = [9];

// concat方法
console.log(arr.concat(arr1, arr2));

// slice方法,以数组形式返回,不改变原来数组
console.log(arr.slice(0, 1));

// indexOf与lastIndexOf方法
console.log(arr.indexOf(1));
console.log(arr.lastIndexOf(2));

// join方法,拼接之后原数组不改变
let newArr1 = arr.concat();
console.log(newArr1.join('/'));

// reverse方法,反转之后原数组改变
let newArr2 = arr.slice(0);
console.log(newArr2.reverse());

// sort方法
let newArr3 = arr.slice(0);
newArr3.push(4);
console.log(newArr3.sort((a, b) => a - b));
console.log(newArr3.sort((a, b) => b - a));

// toString方法,转化为逗号连接字符串,原数组不改变
let newArr4 = arr.slice(0);
console.log(newArr4.toString());

// valueOf方法
let newArr5 = arr.slice(0);
console.log(newArr5.valueOf());

const isEven = x => x % 2 === 0;
// every方法,如果该函数对每个数都返回true则返回true
let arrNew1 = arr.slice(0);
console.log(arrNew1.every(isEven));

// some方法,如果该函数对任一个数返回true则返回true
console.log(arrNew1.some(isEven));

// forEach方法,对每个元素都调用函数,无返回值,原数组不改变
let arrNew2 = arr.slice(0);
console.log(arrNew2.forEach(x => console.log(x ** 2)));
console.log(arrNew2);

// filter方法,每个元素调用函数,返回是true的数组,原数组不改变
console.log(arrNew2.filter(isEven));

// map方法,每个元素调用函数,返回结果组成的数组,原数组不改变
console.log(arrNew2.map(isEven));

// reduce方法,方法接受一个函数作为参数,返回累加到累加器的值
console.log(arrNew2.reduce((pre, cur) => pre + cur * 2));

// Array.from方法,创建新数组,回调函数类似与map效果
let arrNew3 = arr.slice(0);
console.log(Array.from(arrNew3));
console.log(Array.from(arrNew3, x => (x % 2 == 1)));
console.log(Array.from(arrNew3, x => x ** 2));

// Array.of方法,创建新数组,参数是离散点
console.log(Array.of(1, 2, 3));

// fill方法
console.log(new Array(4).fill(1));
console.log(arrNew3.fill(88, 1));

// include方法
console.log(arrNew3.includes(88));

// find和findIndex方法,返回一个数,只看第一个
console.log(arrNew2.find(x => x % 2 == 0));
console.log(arrNew2.findIndex(x => x % 2 == 0));

// copyWithin方法,原数组会改变
let arrNew4 = [1, 2, 3, 4, 5, 6, 7];
console.log(arrNew4.copyWithin(0, 3));
console.log(arrNew4.copyWithin(0, 4));
console.log(arrNew4.copyWithin(0, 3, 5));